function k = gaussK(x1,x2,sigk, c)
% Gaussian Kernel implementation. Adapted by D. Wingate from code written
% by Tijl De Bie. Note: c is the rior variance of V.
%
% Tobias Siegfried, 06/09/2008

%k = exp(-norm(x1-x2)^2/(2*sigk^2));

% Note, this is equivalent to...
% k2 = exp(-(x1-x2)'*(x1-x2)/(2*sigk^2))

k = x1'*x2;

x1sq = x1 .* x1;
x1sum = sum( x1sq, 1 );

x2sq = x2 .* x2;
x2sum = sum( x2sq, 1 );

k = k - x1sum' * ones(1,length(x2sum))/2;
k = k - ones(length(x1sum),1) * x2sum/2;

k = k ./ sigk^2;

k = c * exp(k);